<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActiveRecord::Acts::Versioned::ActMethods::ClassMethods</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActiveRecord::Acts::Versioned::ActMethods::ClassMethods</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../../../files/vendor/plugins/acts_as_versioned/lib/acts_as_versioned_rb.html">
                vendor/plugins/acts_as_versioned/lib/acts_as_versioned.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000025">create_versioned_table</a>&nbsp;&nbsp;
      <a href="#M000026">drop_versioned_table</a>&nbsp;&nbsp;
      <a href="#M000021">find_version</a>&nbsp;&nbsp;
      <a href="#M000022">find_versions</a>&nbsp;&nbsp;
      <a href="#M000024">versioned_class</a>&nbsp;&nbsp;
      <a href="#M000023">versioned_columns</a>&nbsp;&nbsp;
      <a href="#M000028">without_locking</a>&nbsp;&nbsp;
      <a href="#M000027">without_revision</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000025" class="method-detail">
        <a name="M000025"></a>

        <div class="method-heading">
          <a href="#M000025" class="method-signature">
          <span class="method-name">create_versioned_table</span><span class="method-args">(create_table_options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Rake migration task to create the versioned table using options passed to
acts_as_versioned
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000025-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000025-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/acts_as_versioned/lib/acts_as_versioned.rb, line 465</span>
465:           <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">create_versioned_table</span>(<span class="ruby-identifier">create_table_options</span> = {})
466:             <span class="ruby-comment cmt"># create version column in main table if it does not exist</span>
467:             <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">content_columns</span>.<span class="ruby-identifier">find</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span> <span class="ruby-node">%w(version lock_version)</span>.<span class="ruby-identifier">include?</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">name</span> }
468:               <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">connection</span>.<span class="ruby-identifier">add_column</span> <span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">:version</span>, <span class="ruby-identifier">:integer</span>
469:             <span class="ruby-keyword kw">end</span>
470:             
471:             <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">connection</span>.<span class="ruby-identifier">create_table</span>(<span class="ruby-identifier">versioned_table_name</span>, <span class="ruby-identifier">create_table_options</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span>
472:               <span class="ruby-identifier">t</span>.<span class="ruby-identifier">column</span> <span class="ruby-identifier">versioned_foreign_key</span>, <span class="ruby-identifier">:integer</span>
473:               <span class="ruby-identifier">t</span>.<span class="ruby-identifier">column</span> <span class="ruby-identifier">:version</span>, <span class="ruby-identifier">:integer</span>
474:             <span class="ruby-keyword kw">end</span>
475:             
476:             <span class="ruby-identifier">updated_col</span> = <span class="ruby-keyword kw">nil</span>
477:             <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">versioned_columns</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">col</span><span class="ruby-operator">|</span> 
478:               <span class="ruby-identifier">updated_col</span> = <span class="ruby-identifier">col</span> <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">updated_col</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-value str">%(updated_at updated_on)</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">col</span>.<span class="ruby-identifier">name</span>)
479:               <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">connection</span>.<span class="ruby-identifier">add_column</span> <span class="ruby-identifier">versioned_table_name</span>, <span class="ruby-identifier">col</span>.<span class="ruby-identifier">name</span>, <span class="ruby-identifier">col</span>.<span class="ruby-identifier">type</span>, 
480:                 <span class="ruby-identifier">:limit</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">col</span>.<span class="ruby-identifier">limit</span>, 
481:                 <span class="ruby-identifier">:default</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">col</span>.<span class="ruby-identifier">default</span>
482:             <span class="ruby-keyword kw">end</span>
483:         
484:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">type_col</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">columns_hash</span>[<span class="ruby-identifier">inheritance_column</span>]
485:               <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">connection</span>.<span class="ruby-identifier">add_column</span> <span class="ruby-identifier">versioned_table_name</span>, <span class="ruby-identifier">versioned_inheritance_column</span>, <span class="ruby-identifier">type_col</span>.<span class="ruby-identifier">type</span>, 
486:                 <span class="ruby-identifier">:limit</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">type_col</span>.<span class="ruby-identifier">limit</span>, 
487:                 <span class="ruby-identifier">:default</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">type_col</span>.<span class="ruby-identifier">default</span>
488:             <span class="ruby-keyword kw">end</span>
489:     
490:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">updated_col</span>.<span class="ruby-identifier">nil?</span>
491:               <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">connection</span>.<span class="ruby-identifier">add_column</span> <span class="ruby-identifier">versioned_table_name</span>, <span class="ruby-identifier">:updated_at</span>, <span class="ruby-identifier">:timestamp</span>
492:             <span class="ruby-keyword kw">end</span>
493:           <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000026" class="method-detail">
        <a name="M000026"></a>

        <div class="method-heading">
          <a href="#M000026" class="method-signature">
          <span class="method-name">drop_versioned_table</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Rake migration task to drop the versioned table
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000026-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000026-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/acts_as_versioned/lib/acts_as_versioned.rb, line 496</span>
496:           <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">drop_versioned_table</span>
497:             <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">connection</span>.<span class="ruby-identifier">drop_table</span> <span class="ruby-identifier">versioned_table_name</span>
498:           <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000021" class="method-detail">
        <a name="M000021"></a>

        <div class="method-heading">
          <a href="#M000021" class="method-signature">
          <span class="method-name">find_version</span><span class="method-args">(id, version)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Finds a specific version of a specific row of this model
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000021-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000021-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/acts_as_versioned/lib/acts_as_versioned.rb, line 441</span>
441:           <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">find_version</span>(<span class="ruby-identifier">id</span>, <span class="ruby-identifier">version</span>)
442:             <span class="ruby-identifier">find_versions</span>(<span class="ruby-identifier">id</span>, 
443:               <span class="ruby-identifier">:conditions</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-node">&quot;#{versioned_foreign_key} = ? AND version = ?&quot;</span>, <span class="ruby-identifier">id</span>, <span class="ruby-identifier">version</span>], 
444:               <span class="ruby-identifier">:limit</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">1</span>).<span class="ruby-identifier">first</span>
445:           <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000022" class="method-detail">
        <a name="M000022"></a>

        <div class="method-heading">
          <a href="#M000022" class="method-signature">
          <span class="method-name">find_versions</span><span class="method-args">(id, options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Finds versions of a specific model. Takes an options hash like
<tt>find</tt>
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000022-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000022-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/acts_as_versioned/lib/acts_as_versioned.rb, line 448</span>
448:           <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">find_versions</span>(<span class="ruby-identifier">id</span>, <span class="ruby-identifier">options</span> = {})
449:             <span class="ruby-identifier">versioned_class</span>.<span class="ruby-identifier">find</span> <span class="ruby-identifier">:all</span>, {
450:               <span class="ruby-identifier">:conditions</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-node">&quot;#{versioned_foreign_key} = ?&quot;</span>, <span class="ruby-identifier">id</span>],
451:               <span class="ruby-identifier">:order</span>      =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'version'</span> }.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">options</span>)
452:           <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000024" class="method-detail">
        <a name="M000024"></a>

        <div class="method-heading">
          <a href="#M000024" class="method-signature">
          <span class="method-name">versioned_class</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns an instance of the dynamic versioned model
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000024-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000024-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/acts_as_versioned/lib/acts_as_versioned.rb, line 460</span>
460:           <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">versioned_class</span>
461:             <span class="ruby-identifier">const_get</span> <span class="ruby-identifier">versioned_class_name</span>
462:           <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000023" class="method-detail">
        <a name="M000023"></a>

        <div class="method-heading">
          <a href="#M000023" class="method-signature">
          <span class="method-name">versioned_columns</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns an array of columns that are versioned. See non_versioned_columns
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000023-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000023-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/acts_as_versioned/lib/acts_as_versioned.rb, line 455</span>
455:           <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">versioned_columns</span>
456:             <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">columns</span>.<span class="ruby-identifier">select</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span> <span class="ruby-operator">!</span><span class="ruby-identifier">non_versioned_columns</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">c</span>.<span class="ruby-identifier">name</span>) }
457:           <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000028" class="method-detail">
        <a name="M000028"></a>

        <div class="method-heading">
          <a href="#M000028" class="method-signature">
          <span class="method-name">without_locking</span><span class="method-args">(&amp;block)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Turns off optimistic locking for the duration of the block
</p>
<pre>
  Foo.without_locking do
    @foo.save
  end
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000028-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000028-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/acts_as_versioned/lib/acts_as_versioned.rb, line 528</span>
528:           <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">without_locking</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
529:             <span class="ruby-identifier">current</span> = <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">lock_optimistically</span>
530:             <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">lock_optimistically</span> = <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">current</span>
531:             <span class="ruby-identifier">result</span> = <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>
532:             <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">lock_optimistically</span> = <span class="ruby-keyword kw">true</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">current</span>
533:             <span class="ruby-identifier">result</span>
534:           <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000027" class="method-detail">
        <a name="M000027"></a>

        <div class="method-heading">
          <a href="#M000027" class="method-signature">
          <span class="method-name">without_revision</span><span class="method-args">(&amp;block)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Executes the block with the versioning callbacks disabled.
</p>
<pre>
  Foo.without_revision do
    @foo.save
  end
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000027-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000027-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/acts_as_versioned/lib/acts_as_versioned.rb, line 506</span>
506:           <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">without_revision</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
507:             <span class="ruby-identifier">class_eval</span> <span class="ruby-keyword kw">do</span> 
508:               <span class="ruby-constant">CALLBACKS</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">attr_name</span><span class="ruby-operator">|</span>
509:                 <span class="ruby-identifier">alias_method</span> <span class="ruby-node">&quot;orig_#{attr_name}&quot;</span>.<span class="ruby-identifier">to_sym</span>, <span class="ruby-identifier">attr_name</span>
510:                 <span class="ruby-identifier">alias_method</span> <span class="ruby-identifier">attr_name</span>, <span class="ruby-identifier">:empty_callback</span>
511:               <span class="ruby-keyword kw">end</span>
512:             <span class="ruby-keyword kw">end</span>
513:             <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>
514:           <span class="ruby-keyword kw">ensure</span>
515:             <span class="ruby-identifier">class_eval</span> <span class="ruby-keyword kw">do</span> 
516:               <span class="ruby-constant">CALLBACKS</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">attr_name</span><span class="ruby-operator">|</span>
517:                 <span class="ruby-identifier">alias_method</span> <span class="ruby-identifier">attr_name</span>, <span class="ruby-node">&quot;orig_#{attr_name}&quot;</span>.<span class="ruby-identifier">to_sym</span>
518:               <span class="ruby-keyword kw">end</span>
519:             <span class="ruby-keyword kw">end</span>
520:           <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>